<?php
/*首页数据*/
namespace Admin\Model;
use Think\Model;
class MonthPayModel extends Model {
    public function addMonthPay($orderid,$month_pay,$zz_month_pay){
       $order=M('order');
       $where_order['orderid']=$orderid;
       $order_data=$order->field('carnum,uid')->where($where_order)->find();

       $order_operation=M('order_operation');
       $where_order_operation['orderid']=$orderid;
       $where_order_operation['status']=3;
       $order_operation_data=$order_operation->field('create_time')->where($where_order_operation)->find();

       $month= date("m",$order_operation_data['create_time']);
       $year= date("Y",$order_operation_data['create_time']);
       $day= date("d",$order_operation_data['create_time']);
       $order_month_pay=M('order_month_pay');
       for($i=0;$i<=35;$i++){
           $now_year=$year;
           $now_month=$month+$i;
           $now_day=$day;
           if($i+$month>12){
               $year_num=floor(($i+$month) / 12 );
               $now_year=$year+$year_num;
               $now_month=$month+$i-12*$year_num;
           }
           $month_days=date('t', strtotime($now_year.'-'.$now_month.'-1'));
           if($month_days<$day){
               $now_day=$month_days;
           }
           $data=[];
           $data['orderid']=$orderid;
           $data['uid']=$order_data['uid'];
           $data['money']=$month_pay;
           if($zz_month_pay!=0 && $i<12){
              $data['money']=$month_pay+$zz_month_pay;
           }
           $data['pay_month']=$i+1;
           
           $data['pay_time']=strtotime($now_year.'-'.$now_month.'-'.$now_day." 23:59:59");
           $data['status']=0;
           if($i==0){
               $data['status']=1;
           }
           $data['create_time']=time();

           $order_month_pay->add($data);
       } 
    } 
}


?>